import Local_Window_SkillType from './windowSkillType.js'
let SWDA_SkillScene = {};
//=============================================================================
// Scene_Skill
//=============================================================================

// 顶部分类菜单
Scene_Skill.prototype.createSkillTypeWindow = function() {
    const wy = this._helpWindow.height;
    this._skillTypeWindow = new Local_Window_SkillType(0, wy);
    this._skillTypeWindow.setHelpWindow(this._helpWindow);
    //this._skillTypeWindow.setHandler('skill',    this.commandSkill.bind(this));
    this._skillTypeWindow.setHandler('cancel',   this.popScene.bind(this));
    this._skillTypeWindow.setHandler('pagedown', this.nextActor.bind(this));
    this._skillTypeWindow.setHandler('pageup',   this.previousActor.bind(this));
    this.addWindow(this._skillTypeWindow);

    // 设置外观基础值
    const [x, y, width] = [650, 40, 500];
    this._skillTypeWindow.x = x
    this._skillTypeWindow.y = y
    this._skillTypeWindow.width = width
};

Scene_Skill.prototype.createStatusWindow = function() {
    const [wx, wy, ww, wh] = [-24, -24, 600, 400];
    this._statusWindow = new Window_SkillStatus(wx, wy, ww, wh);
    this._statusWindow.reservePortraitImages();
    this.addChildAt(this._statusWindow._portraitSprite,2);    // 在底层显示立绘
    this.addWindow(this._statusWindow);

    this.createActorPageWindow(); // 角色翻页
  };

  // 角色翻页
  Scene_Skill.prototype.createActorPageWindow = function() {
    this._actorPageWindow = new Window_ActorPage();
    this._actorPageWindow.activate();
    this._actorPageWindow.setScene(this);
    this.addWindow(this._actorPageWindow);
};
Scene_Skill.prototype.createItemWindow = function() {
    const [x, y, width, height] = [680, this._skillTypeWindow.y + 65, 482, 480];
    this._itemWindow = new Window_SkillList(x, y, width, height);
    this._itemWindow.opacity = 0
    this._itemWindow._scrollbar.setOffset(5)
    this._itemWindow.setHelpWindow(this._helpWindow);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
    this._skillTypeWindow.setSkillWindow(this._itemWindow);
    this.addWindow(this._itemWindow);
    this._itemWindow.activate();
    //this._itemWindow.selectLast();//目前报错
};


Scene_Skill.prototype.refreshActor = function() {
    var actor = this.actor();
    this._skillTypeWindow.setActor(actor);
    this._statusWindow.setActor(actor);
    this._itemWindow.setActor(actor);
};


// 详细说明菜单
SWDA_SkillScene.Scene_Skill_createHelpWindow = Scene_Skill.prototype.createHelpWindow;
Scene_Skill.prototype.createHelpWindow = function () {
    SWDA_SkillScene.Scene_Skill_createHelpWindow.call(this)
    this._helpWindow.x = 0;
    this._helpWindow.y = Graphics.boxHeight - this._helpWindow.height
}

Scene_Skill.prototype.setActorWindowPosition = function () {
    const _window = this._actorWindow
    _window.x = 0.2 * Graphics.boxWidth
    _window.y = 0.4 * Graphics.boxHeight
}

SWDA_SkillScene.Scene_Skill_onItemOk = Scene_Skill.prototype.onItemOk;
Scene_Skill.prototype.onItemOk = function() {
    SWDA_SkillScene.Scene_Skill_onItemOk.call(this);
    this.setActorWindowPosition()
    this._skillTypeWindow.deactivate();
    this._actorPageWindow.deactivate();
    this._actorPageWindow.hide();
};

SWDA_SkillScene.Scene_Skill_onItemCancel = Scene_Skill.prototype.onItemCancel;
Scene_Skill.prototype.onItemCancel = function() {
    SWDA_SkillScene.Scene_Skill_onItemCancel.call(this);
    this._skillTypeWindow.activate();
    this._actorPageWindow.activate();
    this._actorPageWindow.show();
};

SWDA_SkillScene.Scene_Skill_onActorOk = Scene_Skill.prototype.onActorOk;
Scene_Skill.prototype.onActorOk = function() {
    SWDA_SkillScene.Scene_Skill_onActorOk.call(this);
    /*
    if (this.canUse()) {
        this._skillTypeWindow.activate();
    }
    */
};

SWDA_SkillScene.Scene_Skill_onActorOCancel = Scene_Skill.prototype.onActorCancel;
Scene_ItemBase.prototype.onActorCancel = function() {
    SWDA_SkillScene.Scene_Skill_onActorOCancel.call(this);
    this._skillTypeWindow.activate();
    this._actorPageWindow.activate();
    this._actorPageWindow.show();
};
